package com.zjy.heath_ms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zjy.heath_ms.mapper.UserMapper;
import com.zjy.heath_ms.pojo.User;
import com.zjy.heath_ms.service.UserService;
import com.zjy.heath_ms.utils.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 项目名 heath_ms
 * 类名  UserServiceImpl
 * 作者 lzq
 * 创建时间  2025/5/10 11:55
 */
@Service
@Transactional
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Override
    public User login(String username, String password) {
        LambdaQueryWrapper<User> userLambdaQueryWrapper = new LambdaQueryWrapper<>();
        userLambdaQueryWrapper.eq(User::getUsername, username);
        userLambdaQueryWrapper.eq(User::getPassword, MD5Utils.md5(password));
        User user = baseMapper.selectOne(userLambdaQueryWrapper);
        return user;
    }

    @Override
    public boolean editPasswordByUserId(Integer userId, String password) {
        User user = new User();
        user.setPassword(MD5Utils.md5(password));
        int res = baseMapper.update(user, new LambdaQueryWrapper<User>().eq(User::getId, userId));
        return res > 0;
    }
}
